export interface MeetingEntity {
	/**节点ID */
	id: string
	/**父节点ID */
	parent_id: string
	/**mtKey */
	mt_key: string
	/**1:上级；2本级；3：下级 */
	conf_level: 1 | 2 | 3
	/**会议结点的mtid */
	cascade_id: string
	/**	会议名称 */
	name: string
	/**e164 */
	conf_id: string
	/**所在mcu ip */
	ip?: string
	/**在线状态：0-不在线，1-在线*/
	online: 0 | 1
	/**静音：0-不静音，1-静音 */
	silence: 0 | 1
	/**哑音：0-不哑音，1-哑音 */
	mute: 0 | 1
	/**是否发送双流： 1-发送，0-不发送 */
	doubleflow: 0 | 1
	/**是否上传 0：否；1：是 */
	up_mt: 0 | 1
	/**电视墙：0-不在线，1-在线*/
	tvwall: 0 | 1
	/**画面合成：0-不静音，1-静音 */
	vmp: 0 | 1
	//**是否主讲：1-主讲，0-不是 */
	speaker?: 0 | 1
	/**终端顺序 */
	index: number
}
export type MeetingStatus = ReturnType<typeof transStatus>
function transStatus(meeting: MeetingEntity) {
	return {
		isOnline: !!meeting.online,
		isSilence: !!meeting.silence,
		isMute: !!meeting.mute,
		isDoubleFlow: !!meeting.doubleflow,
		isUpMt: !!meeting.up_mt,
		isTvWall: !!meeting.tvwall,
		isVmp: !!meeting.vmp,
		isSpeaker: !!meeting.speaker,
		get isManager() {
			return this.isSpeaker
		},
	}
}
export class Meeting {
	isMt: false = false
	id: string
	mtKey: string
	parentId: string
	confLevel: 1 | 2 | 3
	smcuMtid: string
	name: string
	mtType: 8 | '' | 7
	index: number
	account: string
	accountType: number
	ip?: string
	status: MeetingStatus
	constructor(meeting: MeetingEntity) {
		this.id = meeting.id
		this.mtKey = meeting.mt_key
		this.name = meeting.name
		this.parentId = meeting.parent_id
		this.confLevel = meeting.conf_level
		this.smcuMtid = meeting.cascade_id
		this.index = meeting.index
		this.mtType = meeting.conf_level === 1 ? 8 : meeting.conf_level === 2 ? '' : 7
		this.account = meeting.conf_id
		this.accountType = 5
		this.ip = meeting.ip
		this.status = transStatus(meeting)
	}
}
export function revert_meeting(meeting: Meeting): MeetingEntity & { isMt: false } {
	return {
		isMt: false,
		id: meeting.id,
		mt_key: meeting.mtKey,
		parent_id: meeting.parentId,
		conf_level: meeting.confLevel,
		cascade_id: meeting.smcuMtid,
		name: meeting.name,
		conf_id: meeting.account,
		index: meeting.index,
		online: meeting.status.isOnline ? 1 : 0,
		silence: meeting.status.isSilence ? 1 : 0,
		mute: meeting.status.isMute ? 1 : 0,
		doubleflow: meeting.status.isDoubleFlow ? 1 : 0,
		up_mt: meeting.status.isUpMt ? 1 : 0,
		tvwall: meeting.status.isTvWall ? 1 : 0,
		vmp: meeting.status.isVmp ? 1 : 0,
		speaker: meeting.status.isSpeaker ? 1 : 0,
		ip: meeting.ip,
	}
}
